package drg_group.taizhou_2022.MDC;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import drg_group.taizhou_2022.Base;
import drg_group.taizhou_2022.MedicalRecord;
import drg_group.taizhou_2022.ADRG.*;

public class MDCN{
    public static String group(MedicalRecord record){
        String[] mdc_zd={"N81.100","C51.001","N98.900","N85.600","N90.401","S38.200x006","S37.600x002","A18.111+N74.1*","D39.000x002","N94.600","D28.204","S39.901","Q50.301","N80.000","N89.805","N73.002","C57.803","Q52.800x004","C79.800x228","N88.200x001","N94.500","N70.100","N80.100x001","N73.202","C55.x00","C57.800x005","D48.127","S31.402","N75.100","N88.800x010","N81.101","C57.701","N86.x01","N89.400","N70.002","N89.802","N92.601","E28.300x008","T28.800x002","N90.700","N92.400","N81.203","N83.903","N76.500","R87.600","C58.x00x003","N88.300","N90.902","N76.401","D26.000","N83.205","N83.500x004","R93.800x007","N73.103","T28.300x001","C79.600","N80.602","N85.000x002","Q50.603","C46.700x001","R87.300","D28.203","N76.400","N89.001","N85.812","N82.900","D26.100x002","C53.100","N70.102","E28.300x005","N91.100","D06.700","D28.100","Q50.600x903","N94.300","N85.808","D39.702","A18.112+N74.0*","N85.813","N83.800x015","Q50.303","A56.101+N74.4*","Q52.700x003","S37.610","C79.800x219","N80.601","D06.100","T19.202","N80.900","N80.800x011","C54.001","N90.901","D39.203","Q52.402","Q50.601","N88.806","Q52.700x005","N88.803","N90.400","N81.801","C79.823","N99.807","N99.800x003","N89.600x001","C79.800x213","N97.200x001","C51.200","N83.700","D28.700x001","N90.804","C57.802","N76.000x003","A54.004","D28.200x002","C79.814","C52.x00","N85.816","T83.400x001","Q52.702","Q56.400","D26.701","N93.900","N96.x00","C53.800","S37.410","N90.808","N85.400","T28.300x003","N76.201","N73.800x002","N70.902","N85.500","N90.800x011","C79.812","Q51.800x007","C79.800x223","N89.801","N90.500","N90.300","N83.807","D39.005","N95.900x001","Q50.200","N81.201","D28.202","N80.802","N83.902","N89.200","A18.114+N74.1*","N80.808","Z31.300x001","N81.200","N90.802","N85.001","D39.001","C48.100x006","N80.500","N90.800x024","N80.302","D25.200x002","N91.500","N94.802","N83.100","S37.601","N97.801","N80.501","Q27.813","N91.400","N84.100","N83.601","N73.102","N90.403","N85.402","N72.x00x006","N90.501","D39.701","N94.803","A18.100x032","N73.606","N80.807","S31.400x001","Z52.800x001","T83.303","A18.100x030+N77.0*","D28.201","N80.600","N82.103","C79.800x209","N94.000","T28.300x002","N85.811","N85.815","N81.301","C57.900","N86.x00x004","D39.901","C79.824","D28.000x002","N80.301","N89.100","N98.800","D18.000x854","D25.100x002","N88.000","N85.000","N73.600","D07.100","N72.x02","N83.501","Q51.800x012","C76.307","A56.002","B37.301+N77.1*","D25.900x001","N82.902","N83.800x016","N94.800x009","D06.000","Q51.800x011","N83.800x017","N70.901","N83.204","N83.802","A56.004","N76.600","N85.200","N92.200","N70.906","N97.400x002","Q85.900x016","N83.503","Q52.401","N71.002","N81.800x005","N71.102","Q50.302","R93.800x006","R93.803","D06.900x002","N81.803","C57.801","N85.809","N94.806","D25.901","N72.x03","N82.303","T83.400","D39.900x001","N88.807","N85.403","C79.800x205","B37.302+N77.1*","D07.301","N84.302","N99.800x007","Q56.200","N82.502","C57.101","N88.804","N88.102","N85.003","Q52.406","N70.900x007","N94.400","Q52.408","N87.000","A18.113+N74.1*","N91.200x002","C79.800x211","N85.803","N76.802","N97.900","A18.102","B37.300+N77.1*","E89.400x001","D28.000","N89.503","Q51.000","Z01.800x003","C58.x00","D39.003","N70.103","N83.808","N80.803","E28.200","N73.801","R87.800","Q50.000","N83.800x013","C79.800x216","N93.901","N94.100","N91.200","N73.003","N70.104","N94.805","D39.100x003","D39.000x001","N80.800x010","N81.900","N90.601","N89.807","N82.000","Q51.001","A54.102","S30.200x007","D39.704","N80.001","N73.101","N73.902","N82.501","N89.901","C57.300","C79.800x214","B26.800x009+N74.8*","N75.000","N71.001","R87.500","Q52.000","N84.000","N83.803","N71.901","Z31.100","N80.801","C79.800x206","N92.000x002","C51.800","L29.200","N92.000x001","Q50.502","N73.605","D18.000x856","N75.801","N81.500","I89.800x033","N83.100x002","Q52.901","N93.801","N70.903","N83.805","N90.302","N90.100","N98.100","Q52.405","N85.000x004","N89.804","N82.300","D39.902","N92.400x003","N76.001","N99.800x010","Q51.808","C53.900","N89.502","N85.700","I77.009","N93.000x001","Q50.504","N85.805","I86.200","N83.811","Q50.600","N88.802","T83.304","I89.800x032","C79.833","N83.812","N84.800x002","N99.201","N82.901","R87.000","N95.101","N73.104","E28.302","N90.000","C77.500x003","Q52.400x006","N90.800x010","Z01.400x001","N87.001","N89.810","N83.504","N75.802","Q51.901","A56.100x003+N74.4*","C79.821","N82.500","N84.300","R87.400","E28.100","C57.300x001","N85.804","N97.400x001","D07.100x002","N80.303","D26.100","Q51.201","S38.200x002","A54.005","D39.703","T28.800x003","C56.x00","N88.808","N89.600x002","N85.401","D39.710","Q52.104","S31.401","C57.000x002","N85.300","Q52.103","N84.001","Q56.000","Q50.600x904","C54.800","N95.000","D07.000","C79.800x215","N87.002","Q51.900","N84.301","N92.100x001","N80.200","Z31.200x003","N89.806","D07.304","N80.401","C57.100","D39.709","C79.800x202","N92.600","D39.200x002","N81.602","N76.100x002","C57.400","S30.200x010","R87.200","I89.000x019","E28.303","Q50.000x011","N83.100x003","Q52.200","N88.805","C51.100","N76.000x001","Q52.300","Q51.600","N73.300","N84.200","N76.000x004","N89.811","N85.101","E28.300x001","N90.200","E28.000","C54.300","D28.200x003","N70.900","N76.100x001","C54.000","D07.303","N76.101","N87.100","Z31.300x002","S37.600","T19.201","Q52.400x007","N73.604","N81.500x003","A60.000x003+N77.1*","E30.900","N95.200","N92.400x004","N90.101","N73.400","N97.300","N32.004","A51.400x009+N74.2*","N97.800x004","Q51.000x001","T83.302","Q52.404","N73.603","N80.800x007","Q50.300x101","N85.800x003","N80.200x001","S31.400x003","N70.900x003","S37.602","E28.800x002","N83.201","N82.101","N92.500","Q52.703","Q52.101","N90.301","D18.000x817","D25.900","D27.x00","N90.800x025","N94.200","Q51.203","S39.902","N82.801","C57.700","N99.300","T28.800x001","N82.301","N88.400","N88.900","N89.700","R87.700","N96.x00x003","D07.200","C79.813","S30.200x008","A56.104+N74.4*","N73.602","Z31.000x001","D25.200","N71.900x001","N83.000x002","N90.600","N92.101","R87.100","E28.200x003","N73.501","N85.802","N87.901","N82.401","N70.001","N95.201","Q50.100","N76.601","D39.706","N95.800","N83.206","N85.806","Q51.400","Q51.502","C53.801","N82.102","N85.100","N94.804","A54.201+N74.3*","D28.900","N87.200x001","N95.100","N97.100x001","N81.800x004","N72.x01","N83.804","N88.100","N76.301","N97.000x001","D39.101","N89.601","Q52.601","N90.811","N76.300x001","N85.810","N83.600","D25.100x001","N99.800x005","C79.822","N83.810","N89.803","C58.x00x002","N85.814","Q52.403","I86.300","N83.800x021","N81.601","N97.901","C54.200","I89.000x018","N71.101","T83.305","A54.003","N90.402","Q51.805","N83.101","N70.905","E28.300x002","N80.300","S37.710","N95.300x001","A54.200x004+N74.3*","Q51.801","N80.603","C57.800x004","N89.600","C57.702","N91.300","N83.202","D39.202","N73.903","N89.101","Q27.816","A18.100x019+N77.1*","D39.204","N92.300","Q50.503","N90.806","N97.101","A18.100x024+N74.1*","N98.000","C79.800x220","N72.x00x003","A56.003","D17.300x003","N87.900","N89.809","D39.700x001","N75.900","D18.000x853","D26.900","C79.800x222","N85.807","N81.000","Q51.202","N98.200","D07.200x002","Q50.000x021","N73.500","N87.101","N83.401","D17.700x024","N90.807","N97.200x002","N76.801","N83.500x007","Q50.602","A18.100x026+N74.1*","Q56.300","A59.002+N77.1*","T19.300x001","D26.702","N99.200","N83.001","D18.000x824","C45.100","Z31.201","C54.900","N89.300","Q51.300","N88.201","N83.806","Q51.100","D20.103","N85.300x001","D39.200x001","N89.800x009","N86.x02","D25.000x002","D26.700","Q52.700x004","T83.301","N80.806","N89.501","D39.700x002","E89.401","D39.004","N83.800x012","N90.810","B37.300x002+N77.1*","D39.201","N81.500x002","D28.205","N83.203","N85.404","N76.000x006","N81.400","N96.x00x002","Q27.814","S37.400","N90.803","N83.207","E28.900","S37.510","Z31.200","N73.201","N99.801","D39.002","N83.901","C79.800x218","Q51.501","N81.300","D39.903","N81.202","S37.810","Q50.400","Q51.804","Q51.100x001","D39.705","D28.206","N70.000","N73.203","N83.801","N70.904","N83.000","N90.805","M35.202+N77.8*","N84.900","N97.902","N81.600","N92.400x001","D39.708","S37.500","N85.801","N89.000","N82.900x003","D39.100x001","C51.900","N97.100x003","Q50.401","Q51.803","E28.301","N81.802","N90.800x009","N94.808","Q51.802","N85.600x001","Q51.806","C54.100","N98.300","N83.300x002","N80.804","N83.502","S31.400x002","N94.807","N94.900","N80.805","N80.100","D39.707","N90.404","N76.200","N76.000","Q52.407","C57.301","N88.801","N82.100x001","N90.801","N91.000","C53.000","D25.000","N71.902","N80.809","N90.809","Q85.900x047","N90.001","N83.300x001","A56.100x004+N74.4*","Q52.500x001","C57.200","N82.200","C51.000","N90.701","N81.102","N83.809","N85.002","N92.401","N85.901","N73.600x006","Q52.701","D07.302","N73.001","S38.200x001","N89.808","N88.101","D06.900","D27.x01","A18.115+N74.1*","E89.400x002","C56.x00x003","N73.601","N90.800x012","S30.207","Q50.501","C57.000","N83.102","Q85.900x045","N70.101"};
        String[] dept_list={};
        if (!(true && Base.contains(mdc_zd,record.zdList[0]) && record.gender!=null && record.gender.equals("2"))){
            return "";
        }
        
        Base.groupMessages.putMessage(record.Index,"符合MDCN入组条件，匹配规则：主诊断匹配、女性");
        String result;

        result=NA1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NA2.group(record);
        if (result.length()>0){
            return result;
        }

        result=NB1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NC1.group(record);
        if (result.length()>0){
            return result;
        }

        result=ND1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NE1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NF1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NG1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NJ1.group(record);
        if (result.length()>0){
            return result;
        }

        if (false && record.ssList!=null && record.ssList.length>0  && Base.intersect(Base.SS_VALID,record.ssList)){
            Base.groupMessages.putMessage(record.Index,"符合NQY入组条件，存在有效手术操作："+String.join(",",Base.Intersect(record.ssList,Base.SS_VALID)));
            return "NQY";
        }

        result=NR1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NS1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NZ1.group(record);
        if (result.length()>0){
            return result;
        }

        Base.groupMessages.putMessage(record.Index,"不符合MDCN的ADRG入组条件");
        return "";
    }
}

